﻿using Common;
using NursingDocumentInfoSystem.ClinicRecord;
using NursingFormSystem.BloodGlucoseMonitoring;
using NursingFormSystem.InfantBaby;
using NursingFormSystem.Model;
using NursingFormSystem.Notice;
using NursingFormSystem.TemperatureRecord;
using NursingFormSystem.Version;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class Menu : Form
    {
        public Menu()
        {
            InitializeComponent();
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("0", "00000000000");
            dic.Add("1", "11111111111");
            dic.Add("2", "22222222222");
            dic.Add("3", "33333333333");

            BindingSource bs = new BindingSource();
            bs.DataSource = dic;
            comboBox1.DataSource = bs;
            comboBox1.ValueMember = "Key";
            comboBox1.DisplayMember = "Value";
        }

        string[] UserParam = new string[8];
        public static Tb_User LoginUser;
        public Tb_User InitLoginUser(string[] UserParam)
        {
            //if (LoginUser == null)
            //{
            LoginUser = new Tb_User();
            LoginUser.UserId = UserParam[0];
            LoginUser.UserName = UserParam[1];
            LoginUser.DepartmentCode = UserParam[2];
            LoginUser.DepartmentName = UserParam[3];
            LoginUser.JobTitle = UserParam[4];
            LoginUser.PositionTitle = UserParam[5];
            //}
            return LoginUser;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = comboBox1.SelectedValue.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MainNursingForm mnf = new MainNursingForm(UserParam);
            mnf.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //string serverAddress = txtServerAddress.Text;
            //string userIdCardNum = txtUserIdCardNum.Text;
            //string sealImageBase64;
            //string sealImageType;
            //string message = "";
            //ElectronicSignature es = new ElectronicSignature(LoginUser);
            //es.GetSealImageByCardNum(serverAddress, userIdCardNum, out sealImageBase64, out sealImageType, out message);
            //txtSealImageBase64.Text = sealImageBase64;
            //txtsealImageType.Text = sealImageType;
            //txtMessage.Text = message;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            CreateTable();
        }
        public void CreateTable()
        {
            //创建表
            DataTable dt = new DataTable();

            //1、添加列
            dt.Columns.Add("Name", typeof(string)); //数据类型为 文本

            dt.Columns.Add("Age", typeof(Int32));
            dt.Columns.Add("Time", typeof(DateTime));

            //2、通过列架构添加列
            //DataColumn age = new DataColumn("Age", typeof(Int32));   //数据类型为 整形
            //DataColumn Time = new DataColumn("Time", typeof(DateTime)); //数据类型为 时间
            //dt.Columns.Add(age);
            //dt.Columns.Add(Time);

            ////1、添加空行
            //DataRow dr1 = dt.NewRow();
            //dt.Rows.Add(dr1);

            ////2、添加空行
            //dt.Rows.Add();

            ////3、添加数据行
            //DataRow dr2 = dt.NewRow();
            //dr2[0] = "张三"; //通过索引赋值
            //dr2[1] = 23;
            //dr2["Time"] = DateTime.Now;//通过名称赋值
            //dt.Rows.Add(dr2);

            //4、通过行框架添加
            dt.Rows.Add("李四", 25, DateTime.Now);//Add你们参数的数据顺序要和dt中的列顺对应

        }

        private void button4_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("c1", typeof(int));
            dt.Columns.Add("c2", typeof(string));
            dt.Columns.Add("c3", typeof(int));


            dt.Rows.Add(1, "技术部", 130);
            dt.Rows.Add(2, "产品部", 200);

            dt.Rows.Add(3, "市场部", 130);
            dt.Rows.Add(3, "市场部", 30);

            var query = from d in dt.AsEnumerable()
                        group d by d.Field<string>("c2") into g
                        select new
                        {
                            c2 = g.Key,
                            c3 = g.Sum(t => t.Field<int>("c3"))
                            //c3 = g.Count(t => t.Field<int>("c3"))
                        };
            query.ToList().ForEach(q => MessageBox.Show(string.Format("{0},{1}", q.c2, q.c3)));
        }

        #region 登陆
        private void button7_Click(object sender, EventArgs e)
        {
            if (!isLogin(0))//电签
            {
                MessageBox.Show("登陆失败");
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            if (!isLogin(92))//急诊
            {
                MessageBox.Show("登陆失败");
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (!isLogin(4))
            {
                MessageBox.Show("登陆失败");
            }
        }
        private void button17_Click(object sender, EventArgs e)
        {
            if (!isLogin(16))
            {
                MessageBox.Show("登陆失败");
            }
        }
        private void button18_Click(object sender, EventArgs e)
        {
            if (!isLogin(20))
            {
                MessageBox.Show("登陆失败");
            }
        }
        private void button19_Click(object sender, EventArgs e)
        {
            if (!isLogin(23))
            {
                MessageBox.Show("登陆失败");
            }
        }
        private bool isLogin(int departmentId)
        {
            bool flag = false;
            switch (departmentId)
            {
                case 0:
                    UserParam[0] = "C8888";
                    UserParam[1] = "陈信剑";
                    UserParam[2] = "N160000";
                    UserParam[3] = "N16病区";
                    UserParam[4] = "护士长";
                    UserParam[5] = "护士";
                    UserParam[6] = "N160000";
                    UserParam[7] = "N16病区";
                    flag = true;
                    break;
                case 4:
                    UserParam[0] = "C361";
                    UserParam[1] = "张平红";
                    UserParam[2] = "104B000";
                    UserParam[3] = "四病区";
                    UserParam[4] = "护士";
                    UserParam[5] = "护士";
                    UserParam[6] = "104B100";
                    UserParam[7] = "四病区";
                    flag = true;
                    break;
                case 16:
                    UserParam[0] = "C551";
                    UserParam[1] = "陈美君";
                    UserParam[2] = "N160000";
                    UserParam[3] = "N16病区";
                    UserParam[4] = "护士长";
                    UserParam[5] = "护士";
                    UserParam[6] = "N160000";
                    UserParam[7] = "N16病区";
                    flag = true;
                    break;
                case 20:
                    UserParam[0] = "C706";
                    UserParam[1] = "陈冰冰";
                    UserParam[2] = "N200000";
                    UserParam[3] = "N20病区";
                    UserParam[4] = "护士长";
                    UserParam[5] = "护士";
                    UserParam[6] = "N200000";
                    UserParam[7] = "N20病区";
                    flag = true;
                    break;
                case 23:
                    UserParam[0] = "C486";
                    UserParam[1] = "林咏蔚";
                    UserParam[2] = "N230000";
                    UserParam[3] = "N23病区";
                    UserParam[4] = "护士长";
                    UserParam[5] = "护士";
                    UserParam[6] = "N230000";
                    UserParam[7] = "N23病区";
                    flag = true;
                    break;
                case 92:
                    UserParam[0] = "C775";
                    UserParam[1] = "郑长富";
                    UserParam[2] = "N920000";
                    UserParam[3] = "N急诊病区";
                    UserParam[4] = "护士长";
                    UserParam[5] = "护士";
                    UserParam[6] = "N920000";
                    UserParam[7] = "N急诊病区";
                    flag = true;
                    break;
                case 122:
                    UserParam[0] = "C348";
                    UserParam[1] = "林秋萍";
                    UserParam[2] = "1220000";
                    UserParam[3] = "二十二病区";
                    UserParam[4] = "护士长";
                    UserParam[5] = "护士";
                    UserParam[6] = "1220000";
                    UserParam[7] = "二十二病区";
                    flag = true;
                    break;
            }
            txtDepartmentNo.Text = UserParam[3];
            return flag;
        }
        #endregion

        private void button9_Click(object sender, EventArgs e)
        {
            NoticeMain note = new NoticeMain(UserParam);
            note.Show();
        }

        private void button33_Click(object sender, EventArgs e)
        {
            UserParam[0] = "C" + textBox10.Text;
            UserParam[1] = textBox3.Text;
            UserParam[2] = textBox4.Text;
            UserParam[3] = textBox5.Text + "病区";
            UserParam[4] = textBox6.Text;
            UserParam[5] = textBox7.Text;
            UserParam[6] = textBox4.Text;
            UserParam[7] = textBox5.Text + "病区";
            txtDepartmentNo.Text = UserParam[3];
            MainNursingForm mnf = new MainNursingForm(UserParam);
            mnf.Show();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Helper h = new Helper(UserParam);
            h.Show();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            string stime = "2019-09-01";
            string etime = "2019-09-30";
            NursingAllPrint f = new NursingAllPrint(stime, etime);
            f.ShowDialog();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (!isLogin(122))
            {
                MessageBox.Show("登陆失败");
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            TemperaList frm = new TemperaList();
            frm.Show();
        }

        private void button14_Click(object sender, EventArgs e)
        {

            InspectionView f = new InspectionView("",textBox11.Text);
            f.ShowDialog();
        }
    }
}
